import is from "is_js"

import {
	CHANGE_TOSAT_MSG,
	SHOW_TOSAT_MSG,
	HIDE_TOSAT_MSG,
	SET_TOSAT_CONTENT,
	SHOW_LOADING_MSG,
	HIDE_LOADING_MSG,
	CHANGE_MPGDIALOG_OPTS
}
from '../types'

const state = {
	toastMsg: {
		type: '123',
		content: '123',
		time: 1000,
		show: false
	},
	loadingMsg: {
		content: '正在加载',
		show: false,
		type: "loading"
	},
	mpjDialogOpts: {
		iconType: 'warn1',
		content: "请申请退款",
		btnContent: "申请退款",
		btnFn: function() {
			alert("哈哈哈");
		},
		show: false
	}
}

const mutations = {
	[CHANGE_TOSAT_MSG](store, show, content, type = "default", time =
		2000000) {
		state.toastMsg.show = show;
		state.toastMsg.content = content;
		state.toastMsg.type = type;

	}, [SHOW_TOSAT_MSG](store) {
		state.toastMsg.show = true;
	}, [HIDE_TOSAT_MSG](store) {
		state.toastMsg.show = false;
	}, [SET_TOSAT_CONTENT](store, content) {
		state.toastMsg.content = content;
	}, [SHOW_LOADING_MSG](store, content) {
		state.loadingMsg.show = true;
		state.loadingMsg.content = content || state.loadingMsg.content;
	}, [HIDE_LOADING_MSG](store) {
		state.loadingMsg.show = false;
	}, [CHANGE_MPGDIALOG_OPTS](store, options) {
		// dispatch(types.CHANGE_MPGDIALOG_OPTS, {
		// 	show: true,
		// 	btnFn: function() {
		// 		alert("xx")
		// 	},
		// 	iconType: "warn",
		// 	content: "正在退款",
		// 	btnContent: ""
		// })
		state.mpjDialogOpts.iconType = is.undefined(options.iconType) ? state.mpjDialogOpts
			.iconType : options.iconType;
		state.mpjDialogOpts.content = is.undefined(options.content) ? state.mpjDialogOpts
			.content : options.content;
		state.mpjDialogOpts.btnContent = is.undefined(options.btnContent) ? state.mpjDialogOpts
			.btnContent : options.btnContent;
		state.mpjDialogOpts.btnFn = is.undefined(options.btnFn) ? state.mpjDialogOpts
			.btnFn : options.btnFn;
		state.mpjDialogOpts.show = is.undefined(options.show) ? state.mpjDialogOpts.show :
			options.show;
	}
}


export default {
	state,
	mutations
}
